package com.s7.widget.recycler.holder;

import android.view.View;
import android.widget.CompoundButton;

import com.s7.widget.recycler.listener.Recycler;

public class BaseViewHolder<T> extends BaseHolder {

    private T data;

    public BaseViewHolder(View itemView) {
        this(itemView, 0);
    }

    public BaseViewHolder(View itemView, int type) {
        super(itemView, type);
    }

    public void setData(T data) {
        this.data = data;
    }

    public T getData() {
        return data;
    }

    public void setOnCheckedChangeListener(final int id, final Recycler.OnCheckedChangeListener mListener) {
        ((CompoundButton) getView(id)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (mListener != null) {
                    mListener.onCheckedChange(buttonView, getRealPosition(), isChecked, data);
                }
            }
        });
    }

    public void setOnClickListener(int id, final Recycler.OnClickListener mListener) {
        getView(id).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onViewClick(v, getRealPosition(), getData());
                }
            }
        });
    }
}
